
**************************************************************************************************************************************************
* Table 3: Effects on transaction costs
* This table reports estimated treatment effects on measures of transaction costs incurred transferring PDS commodities
**************************************************************************************************************************************************



*******************************************************************************
* Household transaction cost estimates - total cost to access ration
*******************************************************************************
use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear


keep if ss_code == "SS01"   //keep surveyed households only 
drop if ghost_final==1
svyset [pw = pweight]

scalar obs = 3960 

*generate baseline variable
gen bl_var = c_cost_to_access_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1


*March
qui svy: mean c_total_access_cost_adj_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

eststo tot_costmar: xi: reg c_total_access_cost_adj_mar17 bl_var bl_var_mi treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

drop bl_var*


*******************************************************************************
* Dealer transaction cost estimates 
*******************************************************************************
use "${SurveyDataDir}/JHePOS_EL1_Dealer_data.dta",clear

merge 1:1 fps_uid using "${SurveyDataDir}/JHePOS_BL_Dealer_data.dta", keepusing(*_y0) nogen

tostring district_code, replace format("%02.0f")
tostring block_code, replace format("%03.0f")
tostring fps_code, replace format("%02.0f")


*Merge in Strata 
merge m:1 block_code using "${AdminDataDir}/blockLevel_strata.dta", keep(3) keepusing(strata)
drop _merge

qui distinct district_code block_code, j
assert `r(ndistinct)' == 132 


svyset [pw = pweight]


*Transaction cost variable
gen b7_9_transaction_cost =  (b7_expense_details_2 + b9_transport_costs)/a14_rc_count
gen b5_transaction_cost_y0 = (b5_storing_ration_y0 + b5_transport_y0)/a14_rc_count


**** full sample
qui svy: mean b7_9_transaction_cost if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

gen bl_var =  b5_transaction_cost_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1


eststo dealer: xi: reg b7_9_transaction_cost treatment bl_var bl_var_mi i.strata [pw = pweight], cluster(block_code)
estadd local sample "Full"
estadd scalar control_mean = `=Mean0[1,1]'

*** restricted sample
qui svy: mean b7_9_transaction_cost if treatment == 0 & fps_new_yesno == 0
qui estat sd
matrix Mean0 = r(mean)


drop *bl_var*
gen bl_var =  b5_transaction_cost_y0 if fps_new_yesno==0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1

eststo dealerBL: xi: reg b7_9_transaction_cost treatment bl_var bl_var_mi i.strata [pw = pweight] if fps_new_yesno == 0, cluster(block_code)
estadd local sample "Restricted"
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/396

drop bl_var*

*******************************************************************************
* Placeholder for admin cost
*******************************************************************************

gen admin = 1
gen bl_var = 0
eststo admin: xi: reg admin treatment bl_var, cluster(block_code)
*the mean PDS distribution cost per RC and the total no of obs come from PDS budget in 2016 
estadd scalar control_mean=143.8
estadd scalar N=.,replace



#delimit ;
esttab tot_costmar dealer*  admin using "${OutputDir}/Table3.tex", 
	label b(%12.2g) se(%12.2g) booktabs replace nocons nolz width(\hsize)
	drop(_cons _Istrata* bl_var*)
	order (treatment)
	coeflabels( treatment "Treatment" )
	stats(r2_a control_mean N percent_obs sample, 
			labels("Adjusted R\textsuperscript{2}" "Reference group mean" "Observations" "\% of sample" "Sample"
				) fmt(2 %12.2g %15.0fc 0))
	star(* .10 ** .05 *** .01) 
	mgroups("\specialCellCenter{Beneficiary \\ costs}" "\specialCellCenter{Dealer \\ costs}" "\specialCellCenter{Government \\ costs}",	
			pattern(1 1 0 1) prefix(\multicolumn{@span}{c}{) suffix(}) 
			span erepeat(\cmidrule(lr){@span}))
	mlabel(none)
	substitute("Standard errors in parentheses" " "
				"\sym{*} \(p<.10\), \sym{**} \(p<.05\), \sym{***} \(p<.01\)" " "
				"\multicolumn{5}{l}{\footnotesize  }\\" " "
				"0         \\" "6.2\sym{\dagger}          \\"
				"(.)         \\" "--         \\"
				".         \\" "         \\"
				"448         \\" "         \\"
				"&                     &" "&                --  &"
				"&                    \\" "&                --  \\"
				"&                     \\" "&               --  \\");
#delimit cr 
eststo clear
